﻿using System;

namespace KLS.PPDS.Utility.Extension
{
    public static class NumberExtension
    {
        public static int ToInt32(this object value)
        {
            return value.ToInt32(0);
        }


        public static int ToInt32(this int? value)
        {
            return value.HasValue ? value.Value : 0;
        }

        public static int ToInt32(this object value, int defaultValue)
        {
            try
            {
                return Convert.ToInt32(value);
            }
            catch { }

            return defaultValue;
        }


        public static double ToDouble(this string value)
        {
            return value.ToDouble(0);
        }

        public static double ToDouble(this object value, double defaultValue)
        {
            try {
                return Convert.ToDouble(value);
            }
            catch { }

            return defaultValue;
        }
    }
}
